<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Games extends CI_Model {

    
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
        
    function getAllGame($tournamentid)
    {
        $query = $this->db->get_where('ss_game', array('enabled' => 1,'tournamentid' => $tournamentid));
        
        return $query->result();
    }

    function get_game($gameid){
    	
    	$query = $this->db->get_where('ss_game', array('gameid' => $gameid));
    	
    	return $query->result();
    	
    }

    function create_game($tournamentid,$home_teamid,$away_teamid,$game_date,$location)
    {
    	$this->tournamentid = $tournamentid;
    	$this->home_teamid = $home_teamid; // please read the below note
    	$this->away_teamid = $away_teamid;
    	$this->game_date = $game_date;
    	$this->location = $location;
    	$this->home_score = 0;
    	$this->away_score = 0;
    	$this->is_finish = 0;
    
    	$this->db->insert('ss_game', $this);
    }
    
    function edit_game($gameid,$tournamentid,$home_teamid,$away_teamid,$game_date,$location,$is_finish)
    {
    	
    	$this->tournamentid = $tournamentid;
    	$this->home_teamid = $home_teamid; // please read the below note
    	$this->away_teamid = $away_teamid;
    	$this->game_date = $game_date;
    	$this->location = $location;
    	$this->is_finish = $is_finish;
    
    	$this->db->update('ss_game', $this, array('gameid' => $gameid));
    }
    
    function delete_game($gameid){
    	$this->db->delete('ss_game', array('gameid' => $gameid));
    }
    
}